home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / SmallTalk / mst.h < prev    next >
C/C++ Source or Header  |  1995-08-25  |  9KB  |  340 lines

  1. /***********************************************************************
  2.  *
  3.  *    generic inclusions.
  4.  *
  5.  ***********************************************************************/
  6.  
  7. /***********************************************************************
  8.  *
  9.  * Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  10.  * Written by Steve Byrne.
  11.  *
  12.  * This file is part of GNU Smalltalk.
  13.  *
  14.  * GNU Smalltalk is free software; you can redistribute it and/or modify it
  15.  * under the terms of the GNU General Public License as published by the Free
  16.  * Software Foundation; either version 1, or (at your option) any later 
  17.  * version.
  18.  * 
  19.  * GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  20.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  21.  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  22.  * more details.
  23.  * 
  24.  * You should have received a copy of the GNU General Public License along with
  25.  * GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  26.  * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  27.  *
  28.  ***********************************************************************/
  29.  
  30.  
  31. /*
  32.  *    Change Log
  33.  * ============================================================================
  34.  * Author      Date       Change 
  35.  * sbb         14 Sep 91      Added edit version support.
  36.  *
  37.  * sbyrne    23 Sep 89      Modifications to support operation on a DECstation 3100.
  38.  *
  39.  * sbyrne    13 Sep 89      Sigh!!! modified pushOOP and setStackTop to move the
  40.  *              objects that they refer to to toSpace...good bye
  41.  *              performance!
  42.  *
  43.  * sbyrne    29 Dec 88      Created.
  44.  *
  45.  */
  46.  
  47. #ifndef __MST__
  48. #define __MST__
  49.  
  50. #include "mstconfig.h"
  51.  
  52. /* The system version flags */
  53. #define sysVersMajor        1 
  54. #define sysVersMinor        2 
  55. #define sysVersEdit        0
  56.  
  57. /* Enable this definition to count different types of byte code executions */
  58. /* #define countingByteCodes */
  59.  
  60.  
  61. #define baseInt            (((unsigned long)3)<<30)
  62. #define highBitMask        (((unsigned long)1)<<31) /* just hi bit */
  63.  
  64. #ifndef USE_BCOPY
  65. #include <memory.h>
  66. #define bcopy(s2, s1, n)  memcpy(s1, s2, n)
  67. #define bzero(s,l) memset(s,'\0',l)
  68. #endif /* USE_BCOPY */
  69.  
  70. /*#if !defined(__STDC__) && (defined(AIX) | defined(mips) | defined(ibm032) || (defined(sun) && !defined(SUNOS40))) */
  71. #if !defined(__STDC__) && defined(OLDCC)
  72. /* for older compilers that don't understand void * and enums are ints */
  73. #define nil            0
  74. typedef char *voidPtr;
  75. #define ENUM_INT(x)           ((int)(x))
  76. typedef int Boolean;
  77. #define false            0
  78. #define true            1
  79.  
  80. #else 
  81. typedef void *voidPtr;
  82. /* old code #define nil            (voidPtr)0 */
  83. #define nil            0
  84. /*old code#define ENUM_INT(x)        (x)*/
  85. #define ENUM_INT(x)        ((int)(x))
  86.  
  87. typedef enum booleanType {
  88.   false,
  89.   true
  90. } Boolean;
  91.  
  92. #endif
  93.  
  94.  
  95. /* Would someone (this means you!) please test this out on this machine and 
  96.  * see if this can be merged with the code above a little more cleanly?
  97.  */
  98. #if defined(hp9000s300)
  99. #undef ENUM_INT
  100. #define ENUM_INT(x)            ((int)(x))
  101. #endif
  102.  
  103. /* The set of checks here should either be expanded, or in the m-*.h files
  104.    there should be a definition that talks about the required alignment
  105.    for doubles, whether they must be on a 4 or 8 byte boundary. */
  106. #if defined(sparc) || defined(hppa)
  107. #define DOUBLE_ALIGNMENT    sizeof(double)
  108. #else
  109. #define DOUBLE_ALIGNMENT    sizeof(long)
  110. #endif
  111.  
  112.  
  113.  
  114. typedef struct StreamStruct    *Stream;
  115.  
  116. typedef struct OOPStruct    *OOP;
  117. typedef struct ObjectStruct    *Object;
  118.  
  119. struct OOPStruct {
  120.   Object    object;
  121. #ifndef NO_FIELDS
  122.   unsigned long flags;
  123. };
  124.  
  125. #define F_FREE        ((unsigned long) 0x80000000)
  126. #define F_SPACE        ((unsigned long) 0x40000000)
  127. #define F_EVEN        ((unsigned long) 0x20000000)
  128. #define F_ODD        ((unsigned long) 0x10000000)
  129. #define F_FAKE        ((unsigned long) 0x08000000)
  130. #define EMPTY_BYTES    ((unsigned long) 0x00000003)
  131.  
  132. /* This macro should only be used right after an allocOOP, when the
  133.  * emptyBytes field is guaranteed to be zero
  134.  */
  135. #define initEmptyBytes(oop, value) \
  136.     ((oop)->flags |= (4 - (value)) & 3)
  137.  
  138. /* Use this one to assign a particular value */
  139. #define setEmptyBytes(oop, value) \
  140.   ( (oop)->flags = ((oop)->flags & ~EMPTY_BYTES) | ((4 - len) & 3) )
  141.  
  142.  
  143. #else
  144.   union {
  145.     struct {
  146. #ifdef BIG_ENDIAN
  147.       unsigned    i_isFree : 1;    /* pack these tighter as needed to make long */
  148.       unsigned  i_evenMark : 1;    /* for OOP table garbage collector */
  149.       unsigned  i_oddMark : 1;    /* for OOP table garbage collector */
  150.       char    i_emptyBytes;   /* 3 number of unused bytes at end; subtract
  151.                    from computed byte length to get the real
  152.                    length of data */
  153.       char    i_inSpace;    /* 0 => space 0, 1 => space 1 */
  154. #else
  155.       char    i_emptyBytes;   /* number of unused bytes at end; subtract
  156.                    from computed byte length to get the real
  157.                    length of data */
  158.       char    i_inSpace;    /* 0 => space 0, 1 => space 1 */
  159.       unsigned    : 13;
  160.       unsigned  i_oddMark : 1;    /* for OOP table garbage collector */
  161.       unsigned  i_evenMark : 1;    /* for OOP table garbage collector */
  162.       unsigned    i_isFree : 1;    /* pack these tighter as needed to make long */
  163. #endif
  164.     } w2_i;
  165. /*    long    w2_prevFree; */
  166.   } w2;
  167. };
  168.  
  169. #define isFree        w2.w2_i.i_isFree
  170. #define emptyBytes    w2.w2_i.i_emptyBytes
  171. #define inSpace        w2.w2_i.i_inSpace
  172. #define evenMark    w2.w2_i.i_evenMark
  173. #define oddMark        w2.w2_i.i_oddMark
  174. /* #define prevFree    w2.w2_prevFree */
  175. #endif
  176.  
  177. /* ### REmoved 31-Dec-91 14:07:11 redundant
  178.    extern struct OOPStruct  oopTable[];
  179.  */
  180.  
  181. /* The header of all objects in the system */
  182. #define OBJ_HEADER \
  183.   long        objSize; /* for now, this is object size in 32bit words*/ \
  184.   OOP        objClass
  185.  
  186. /* just for symbolic use in sizeof's */
  187. typedef struct ObjectHeaderStruct {
  188.   OBJ_HEADER;
  189. } ObjectHeader;
  190.  
  191. #define OBJ_HEADER_SIZE_WORDS    (sizeof(ObjectHeader) / sizeof(long))
  192.  
  193. struct ObjectStruct {
  194.   OBJ_HEADER;
  195.   OOP        data[1];    /* variable length, may not be objects, but
  196.                    will always be at least this big. */
  197. };
  198.  
  199. extern    OOP        *sp;
  200. extern    char        *nilName;
  201. extern    OOP        nilOOP, trueOOP, falseOOP, thisClass;
  202. extern    Boolean        regressionTesting;
  203.  
  204.  
  205. typedef unsigned char Byte;
  206.  
  207. #define TreeNode        void * /* dummy decl */
  208.  
  209.  
  210. /*
  211.  * Macros for common things...can be functions for debugging or can be 
  212.  * macros for speed.
  213.  */
  214.  
  215. #ifndef NO_INLINE_MACROS
  216.  
  217. #ifdef old_code /* Sun Nov 24 16:44:35 1991 */
  218. /**/#define uncheckedPushOOP(oop) \
  219. /**/  *++sp = (oop)
  220. /**/
  221. /**/#define uncheckedSetTop(oop) \
  222. /**/  *sp = (oop)
  223. #endif /* old_code Sun Nov 24 16:44:35 1991 */
  224.  
  225. #define uncheckedPushOOP(oop) \
  226. { \
  227.   *++sp = (oop); \
  228.   }
  229.  
  230. #define uncheckedSetTop(oop) \
  231. { \
  232.   *sp = (oop); \
  233.   }
  234.  
  235. #define pushOOP(oop) \
  236.   uncheckedPushOOP(oop)
  237.  
  238. #ifdef old_code /* Fri Oct 18 20:44:42 1991 */
  239. /**//* YUCK!!!! I HATE TO DO THIS!!!! DAMN GARBAGE COLLECTOR!!!! */
  240. /**/#define pushOOP(oop) \
  241. /**/{ \
  242. /**/  OOP __tempOOP = (oop); \
  243. /**/  maybeMoveOOP(__tempOOP); \
  244. /**/  uncheckedPushOOP(__tempOOP); \
  245. /**/} 
  246. #endif /* old_code Fri Oct 18 20:44:42 1991 */
  247.  
  248. #define popOOP() \
  249.   (*sp--)
  250.  
  251. #define popNOOPs(n) \
  252.   sp -= (n)
  253.  
  254. #define unPop(n) \
  255.   sp += (n)
  256.  
  257. #define stackTop() \
  258.   (*sp)
  259.  
  260. #ifdef old_code /* Fri Oct 18 20:43:36 1991 */
  261. /**//* UGH!!! DAMN GC!!!  I wish we could run without it! */
  262. /**/#define setStackTop(oop) \
  263. /**/{ \
  264. /**/  OOP __tempOOP = (OOP)(oop); \
  265. /**/  maybeMoveOOP(__tempOOP); \
  266. /**/  *sp = __tempOOP; \
  267. /**/}
  268. #endif /* old_code Fri Oct 18 20:43:36 1991 */
  269.  
  270. #define setStackTop(oop) \
  271.   uncheckedSetTop(oop)
  272.  
  273. #define setStackTopInt(i) \
  274.   uncheckedSetTop(fromInt(i))
  275.  
  276. #define setStackTopBoolean(exp) \
  277.   uncheckedSetTop((exp) ? trueOOP : falseOOP)
  278.  
  279. #define stackAt(i) \
  280.   (sp[-(i)])
  281.  
  282. #define pushInt(i) \
  283.   uncheckedPushOOP(fromInt(i))
  284.  
  285. #define popInt() \
  286.   toInt(popOOP())
  287.  
  288. #define pushBoolean(exp) \
  289.   uncheckedPushOOP((exp) ? trueOOP : falseOOP)
  290.  
  291. #define oopToObj(oop) \
  292.   (oop->object)
  293.  
  294. #define oopClass(oop) \
  295.   (oopToObj(oop)->objClass)
  296.  
  297. #define isClass(oop, class) \
  298.   (isOOP(oop) && oopClass(oop) == class)
  299.  
  300. /* integer conversions */
  301.  
  302. #define toInt(oop) \
  303.   ( (long) ((unsigned long)(oop) - baseInt) )
  304.  
  305. #define fromInt(i) \
  306.   (OOP)(((unsigned long)(i) + baseInt) | highBitMask)
  307.  
  308. /*
  309.  * for these, we could probably get away with just hacking the number and
  310.  * setting the high bit.
  311.  */
  312. #define incrInt(i) \
  313.   fromInt(toInt(i) + 1)
  314.  
  315. #define decrInt(i) \
  316.   fromInt(toInt(i) - 1)
  317.  
  318.  
  319.  
  320. #define isInt(oop) \
  321.   ((long)(oop) < 0)
  322.  
  323. #define isOOP(oop) \
  324.   ((long)(oop) >= 0)
  325.  
  326. /* general functions */
  327.  
  328. #define isNil(oop) \
  329.   ((OOP)(oop) == nilOOP)
  330.  
  331. #define isFake(oop) \
  332.   ((oop)->flags & F_FAKE)
  333.  
  334. /* return the number of availble longwords in object, excluding the header */
  335. #define numOOPs(obj) \
  336.   ( 1 + (obj)->objSize - (sizeof(struct ObjectStruct) / sizeof(Object)) )
  337. #endif /* NO_INLINE_MACROS */
  338.  
  339. #endif /* __MST__ */
  340.